<%@ page contentType="text/html; charset=utf-8" import="java.util.List,java.util.Stack,com.wit.po.Area,com.wit.dao.impl.AreaDaoImpl" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>新增保单左侧</title>
<link href="../style/main.css" rel="stylesheet" type="text/css" />
<style>
body#bodyTree{margin:8px;font-size:12px;color:#000;line-height:22px;}
body#bodyTree a{color:#000;text-decoration:none;}
body#bodyTree a:hover{color:#3366CC;padding:2px 0px 0px 0px;}
#bodyTree ul{margin:0;padding:0;list-style:none;background:url(../images/tree/ullist.gif) repeat-y;}
#bodyTree ul li{list-style:none;}
#bodyTree .treeview li{background:transparent url(../images/tree/list.gif) no-repeat left center;padding-left:15px;/*tree list*/}
#bodyTree .treeview li.submenu{background:transparent url(../images/tree/closed.gif) no-repeat left 0px;/*4 sub menu*/}
#bodyTree .treeview li.closefolder{background:transparent url(../images/tree/closed.gif) no-repeat left 0px;/*closefolder style*/}
#bodyTree .treeview li.openfolder{background:transparent url(../images/tree/open.gif) no-repeat left 0px;/*openfolder style*/}
#bodyTree .treeview li.submenu ul{display:none;}
#bodyTree ul li a.cur{font-weight:bold;color:#3366CC;padding:2px 2px 0px 2px;/*the current style*/}
#bodyTree .treeview .submenu i{width:12px;height:12px;font-style:normal;font-size:10px;margin-left:-15px;margin-top:5px;float:left;display:inline;background:url(../images/tree/transparent.gif) no-repeat center; cursor:pointer;}
</style>
<script type="text/javascript" src="../images/tree/simpletreemenu.js"></script>

<script type="text/javascript">
	function select(id)
	{
		var obj = parent.document.getElementById("areaId");
		if(obj != null)
			obj.value=id;
			
		obj = parent.document.getElementById("showTreeDiv");
		if(obj != null)
			obj.style.display = "none";
	}
</script>

</head>
<body id="bodyTree">
<div id="treeDiv" style="text-align: left">
	<%
		List<Area> areaList = AreaDaoImpl.s_GetAreaList();
		if(areaList != null && areaList.size() > 0)
		{
			Area area = areaList.get(0);
			Stack<Integer> areaStack = new Stack<Integer>();
			int listSize = areaList.size();
			int i = 1,tmp;
			if(1 < listSize && area.isParentOf(areaList.get(1)))
				out.print("<ul id=\"areaTree\" class=\"treeview\">\n<li><i></i><a onclick=\"javascript:select('"+area.getAreaId()+"');\" href=\"javascript:void(0);\">"+area.getAreaName()+"</a>\n<ul>\n");
			else
				out.print("<ul id=\"areaTree\" class=\"treeview\">\n<li><i></i><a onclick=\"javascript:select('"+area.getAreaId()+"');\" href=\"javascript:void(0);\">"+area.getAreaName()+"</a>\n");
			areaStack.push(0);
			while(i<listSize)
			{
				area = areaList.get(i);
				if(areaStack.empty() || areaList.get(areaStack.peek()).isParentOf(area))
				{
					if(i+1<listSize && area.isParentOf(areaList.get(i+1)))
						out.print("<li><i></i><a onclick=\"javascript:select('"+area.getAreaId()+"');\" href=\"javascript:void(0);\">"+area.getAreaName()+"</a>\n<ul>\n");
					else
						out.print("<li><i></i><a onclick=\"javascript:select('"+area.getAreaId()+"');\" href=\"javscript:void(0);\">"+area.getAreaName()+"</a>\n");
					areaStack.push(i);
					i++;
				}
				else
				{
					tmp = areaStack.pop();
					if(tmp+1<listSize && areaList.get(tmp).isParentOf(areaList.get(tmp+1)))
						out.print("</ul>\n</li>\n");
					else
						out.print("</li>\n");
				}
			}
			while(!areaStack.empty())
			{
				tmp = areaStack.pop();
				if(tmp+1<listSize && areaList.get(tmp).isParentOf(areaList.get(tmp+1)))
					out.print("</ul>\n</li>\n");
				else
					out.print("</li>\n");
			}
			out.print("</ul>\n");
		}
	%>
	<input type="hidden" name="areaId" id="areaId" />
<script type="text/javascript">
ddtreemenu.createTree("areaTree", true);
</script>
</div>
</body>
</html>